package org.pim.smart.hibernate.domain;

import java.util.Date;
import java.util.List;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;

/**
 * A data access object (DAO) providing persistence and search support for
 * ContactMain entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see org.pim.smart.hibernate.domain.ContactMain
 * @author MyEclipse Persistence Tools
 */

public class ContactMainDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory.getLog(ContactMainDAO.class);
	// property constants
	public static final String CONTACT_NAME = "contactName";
	public static final String CONTACT_GENDER = "contactGender";
	public static final String CONTACT_JOB_TITLE = "contactJobTitle";
	public static final String CONTACT_COMPANY = "contactCompany";
	public static final String CONTACT_NICK = "contactNick";
	public static final String CONTACT_FLAG = "contactFlag";
	public static final String CONTACT_MARRIED = "contactMarried";
	public static final String CONTACT_COUPLE = "contactCouple";
	public static final String CONTACT_IM_GTALK = "contactImGtalk";
	public static final String CONTACT_IM_MSN = "contactImMsn";
	public static final String CONTACT_IM_YAHOO = "contactImYahoo";
	public static final String CONTACT_IM_QQ = "contactImQq";
	public static final String CONTACT_ASSISTANT = "contactAssistant";
	public static final String CONTACT_WORK_DEPARTMENT = "contactWorkDepartment";
	public static final String CONTACT_OFFICE_ADDRESS = "contactOfficeAddress";
	public static final String LAST_UPDATE_BY = "lastUpdateBy";

	public void save(ContactMain transientInstance) {
		log.debug("saving ContactMain instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(ContactMain persistentInstance) {
		log.debug("deleting ContactMain instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public ContactMain findById(java.lang.Integer id) {
		log.debug("getting ContactMain instance with id: " + id);
		try {
			ContactMain instance = (ContactMain) getSession().get(
					"org.pim.smart.hibernate.domain.ContactMain", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(ContactMain instance) {
		log.debug("finding ContactMain instance by example");
		try {
			List results = getSession().createCriteria(
					"org.pim.smart.hibernate.domain.ContactMain").add(
					Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding ContactMain instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from ContactMain as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByContactName(Object contactName) {
		return findByProperty(CONTACT_NAME, contactName);
	}

	public List findByContactGender(Object contactGender) {
		return findByProperty(CONTACT_GENDER, contactGender);
	}

	public List findByContactJobTitle(Object contactJobTitle) {
		return findByProperty(CONTACT_JOB_TITLE, contactJobTitle);
	}

	public List findByContactCompany(Object contactCompany) {
		return findByProperty(CONTACT_COMPANY, contactCompany);
	}

	public List findByContactNick(Object contactNick) {
		return findByProperty(CONTACT_NICK, contactNick);
	}

	public List findByContactFlag(Object contactFlag) {
		return findByProperty(CONTACT_FLAG, contactFlag);
	}

	public List findByContactMarried(Object contactMarried) {
		return findByProperty(CONTACT_MARRIED, contactMarried);
	}

	public List findByContactCouple(Object contactCouple) {
		return findByProperty(CONTACT_COUPLE, contactCouple);
	}

	public List findByContactImGtalk(Object contactImGtalk) {
		return findByProperty(CONTACT_IM_GTALK, contactImGtalk);
	}

	public List findByContactImMsn(Object contactImMsn) {
		return findByProperty(CONTACT_IM_MSN, contactImMsn);
	}

	public List findByContactImYahoo(Object contactImYahoo) {
		return findByProperty(CONTACT_IM_YAHOO, contactImYahoo);
	}

	public List findByContactImQq(Object contactImQq) {
		return findByProperty(CONTACT_IM_QQ, contactImQq);
	}

	public List findByContactAssistant(Object contactAssistant) {
		return findByProperty(CONTACT_ASSISTANT, contactAssistant);
	}

	public List findByContactWorkDepartment(Object contactWorkDepartment) {
		return findByProperty(CONTACT_WORK_DEPARTMENT, contactWorkDepartment);
	}

	public List findByContactOfficeAddress(Object contactOfficeAddress) {
		return findByProperty(CONTACT_OFFICE_ADDRESS, contactOfficeAddress);
	}

	public List findByLastUpdateBy(Object lastUpdateBy) {
		return findByProperty(LAST_UPDATE_BY, lastUpdateBy);
	}

	public List findAll() {
		log.debug("finding all ContactMain instances");
		try {
			String queryString = "from ContactMain";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public ContactMain merge(ContactMain detachedInstance) {
		log.debug("merging ContactMain instance");
		try {
			ContactMain result = (ContactMain) getSession().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(ContactMain instance) {
		log.debug("attaching dirty ContactMain instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(ContactMain instance) {
		log.debug("attaching clean ContactMain instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}